package xiaomi;

import java.util.Scanner;

/**
 * @author Hang
 * @date 2022/9/20
 * @project AutumnOffer
 * @description
 **/
public class Solution1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str;
        int a1,a2;
        int sum = 0,max = 0;
        while(!(str = sc.nextLine()).isEmpty()){
            String[] s = str.split(" ");
            a1 = Integer.parseInt(s[0]);
            a2 = Integer.parseInt(s[1]);
            if(a1>max){
                sum += (a2-a1);
            }else{
                sum += (a2-max);
            }
            max = a2;
        }
        System.out.println(sum);
    }
}
